/*** 
 * @_______________#########_______________________ 
 * @______________############_____________________ 
 * @______________#############____________________ 
 * @_____________##__###########___________________ 
 * @____________###__######_#####__________________ 
 * @____________###_#######___####_________________ 
 * @___________###__##########_####________________ 
 * @__________####__###########_####_______________ 
 * @________#####___###########__#####_____________ 
 * @_______######___###_########___#####___________ 
 * @_______#####___###___########___######_________ 
 * @______######___###__###########___######_______ 
 * @_____######___####_##############__######______ 
 * @____#######__#####################_#######_____ 
 * @____#######__##############################____ 
 * @___#######__######_#################_#######___ 
 * @___#######__######_######_#########___######___ 
 * @___#######____##__######___######_____######___ 
 * @___#######________######____#####_____#####____ 
 * @____######________#####_____#####_____####_____ 
 * @_____#####________####______#####_____###______ 
 * @______#####______;###________###______#________ 
 * @________##_______####________####______________ 
 * @
 * @Author: ipk518 18163976442@163.com
 * @Date: 2024-12-03 16:14:35
 * @LastEditors: ipk518 121206530@qq.com
 * @LastEditTime: 2025-10-14 15:00:24
 * @FilePath: /etws-sxk2307/src/packetResolver/lxCmdV1/hardwareTest.cpp
 * @Description: 
 * @************佛祖保佑************
 * @Copyright (c) 2024 by etws@quyujiang, All Rights Reserved. 
 */

#include "Server.h"
#include "lxCmdV1.h"

/**
 * @description: 预留
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_0(struct cmdDataType* cmd,uint8_t * cmdData)
{
    return 0;
}

/**
 * @description: 发射延迟设置
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_1(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,4,"发射延时设置长度错误.");
    uint16_t m_data[2];
    memcpy((uint8_t *)m_data,cmdData,4);
    Server::Instance().m_sxk.hardwareSync();
    Server::Instance().m_sxk.m_sxkHardTest.prt0_delay = m_data[0];
    Server::Instance().m_sxk.m_sxkHardTest.prt1_delay = m_data[1];
    qlog_i("发射延迟设置:prt0=%d,prt1_2=%d.",m_data[0],m_data[1]);
    Server::Instance().m_event.triggerEvent(WRITE_HARDWARE_TEST);
    return Server::Instance().responseWeb(cmd);
}

/**
 * @description: 发射测试波位设置
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_2(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,4,"发射测试波位设置长度错误.");
    uint16_t m_data[2];
    memcpy((uint8_t *)m_data,cmdData,4);
    Server::Instance().m_sxk.hardwareSync();
    Server::Instance().m_sxk.m_sxkHardTest.sendbeams_set = m_data[0];
    qlog_i("设置发射校准测试波位:%d.",m_data[0]);
    Server::Instance().m_event.triggerEvent(WRITE_HARDWARE_TEST);
    return Server::Instance().responseWeb(cmd);
}

/**
 * @description: 测试模式控制设置
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_3(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,2,"测试模式控制长度错误.");
    uint16_t m_data;
    memcpy((uint8_t *)&m_data,cmdData,2);
    Server::Instance().m_sxk.hardwareSync();
    Server::Instance().m_sxk.m_sxkHardTest.test_mode = m_data;
    Server::Instance().m_sxk.m_sxkHardTest.test_enable = 1;
    qlog_i("测试模式控制:%d.",m_data);
    Server::Instance().m_event.triggerEvent(WRITE_HARDWARE_TEST);
    return Server::Instance().responseWeb(cmd);
}

/**
 * @description: 雷达工作频率控制
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_4(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,2,"雷达工作频率控制长度错误.");
    uint16_t m_data;
    struct cmdDataType cmdHeader;
    uint16_t sendnum = 1;  
    memcpy((uint8_t *)&m_data,cmdData,2);
    Server::Instance().m_sxk.hardwareSync();
    Server::Instance().m_sxk.m_radarSendFreq = m_data;
    qlog_i("雷达工作频率:%dMHz.",m_data);

    m_data = m_data / 1000;
    sendnum = 0x01;  
    cmdHeader.DeviceType = t_controlCmd;
	cmdHeader.source_DevType = CurDeviceType;
	cmdHeader.source_DevNum = ComponentNO;
    cmdHeader.dst_DevType =  PZ_Sub_Unit_S;//PZ
    cmdHeader.dst_DevNum = 0;
    cmdHeader.cmdType = 0;
    cmdHeader.cmdChildType = 7;//TODO:2025/6/26
    cmdHeader.dataLen = 2;
    Server::Instance().separate(s_dds,sendnum,&cmdHeader,(uint8_t *)&m_data);
    return Server::Instance().responseWeb(cmd);
}

/**
 * @description: 伺服角度模拟(1~300)
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_5(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,4,"伺服角度模拟控制长度错误.");
    uint16_t m_data[2];
    memcpy((uint8_t *)m_data,cmdData,4);
    Server::Instance().m_sxk.hardwareSync();
    Server::Instance().m_sxk.m_sxkHardTest.servo_speed = m_data[0];
    Server::Instance().m_sxk.m_sxkHardTest.servo_switch = (m_data[1] == 1)?1:0;
    qlog_i("伺服角度模拟速度:%d.",m_data[0]);
    Server::Instance().m_event.triggerEvent(WRITE_HARDWARE_TEST);
    return Server::Instance().responseWeb(cmd);
}

/**
 * @description: 双偏振量模拟控制
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_6(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,216,"双偏振量模拟长度错误.");
    uint8_t m_data[216];
    memcpy(m_data,cmdData,216);
    Server::Instance().m_sxk.hardwareSync();
    memcpy((uint8_t *)&Server::Instance().m_sxk.m_sxkHardTest.c0p0_h_strength,m_data,216);
    qlog_i("双偏振量模拟");
    Server::Instance().m_event.triggerEvent(WRITE_HARDWARE_TEST);
    return Server::Instance().responseWeb(cmd);
}


/*** 
 * @description: 极化控制
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_7(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,2,"极化控制长度错误.");
    qlog_i("未实现极化控制");

}


/*** 
 * @description: 频综衰减控制
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int hdts_callback_8(struct cmdDataType* cmd,uint8_t * cmdData)
{
    ASSERT_LENGTH(cmd,8,"频综衰减控制长度错误.");
    uint16_t m_data[4];
    memcpy((uint8_t *)m_data,cmdData,8);
    Server::Instance().m_sxk.hardwareSync();
    Server::Instance().m_sxk.m_sxkHardTest.pz_h3714_atten = m_data[0];
    Server::Instance().m_sxk.m_sxkHardTest.pz_v3714_atten = m_data[1];
    Server::Instance().m_sxk.m_sxkHardTest.pz_h424_atten = m_data[2];
    Server::Instance().m_sxk.m_sxkHardTest.pz_v424_atten = m_data[3];
    qlog_i("频综衰减控制:%d,%d,%d,%d.",m_data[0],m_data[1],m_data[2],m_data[3]);
    Server::Instance().m_event.triggerEvent(WRITE_HARDWARE_TEST);
    return Server::Instance().responseWeb(cmd);
}
